from flask import Flask,render_template,jsonify,request
from analysis import selling
from analysis import ttg as TTG,hafu as HAFU,hda as HDA,kj as KJ,c21 as C21,c31 as C31,c31spf as C31spf,c31rspf as C31rspf,c31_111 as C31_111,c21_111 as C21_111
from analysis import sxyc as SXYC
from loaddata import loadData,loadPailieData
app = Flask(__name__)

@app.route('/test')
def test():
    return "服务启动成功！！！"

@app.route('/')
def index():
    #打开主页钱，先去更新一下开奖数据
    # loadData.load()
    return render_template("index.html")

@app.route('/loadByTime')
def loadByTime():
    start = request.args.get('start')
    end = request.args.get('end')
    if start == '' or end == '':
        return "请填写更新时间！！！！"
    else:
        loadData.loadByTime(start,end)
        return "历史更新成功！{}至{}".format(start, end)

@app.route('/loadSelling')
def loadSelling():
    loadData.loadSelling()
    return "今天售卖的数据更新成功"

# 打开未开始的比赛（正在售卖的比赛）
@app.route('/selling_ttg')
def selling_ttg():
    return render_template("selling_ttg.html")

@app.route('/getselling_ttg')
def getselling_ttg():
    r = selling.getSellingTtgDatas()
    return jsonify(r)

# 总进球
@app.route('/ttg')
def ttg():
    matchId = request.args.get('matchId')
    tp = request.args.get('tp')
    return render_template("ttg.html",matchId=matchId,tp=tp)


@app.route('/ttg_ds')
def ttg_ds():
    matchId = request.args.get('matchId')
    sim = request.args.get('sim',"0.31")
    tp = request.args.get('tp')
    start = request.args.get('start', "2024-01-01")
    end = request.args.get('end', "2025-12-31")
    r = TTG.analysisttg(tp,matchId,float(sim),start,end)
    return jsonify(r)


# 总进球统计页面
@app.route('/ttg_tj')
def ttg_tj():
    return render_template("ttg_tj.html")

# 总进球统计数据
@app.route('/ttg_tj_ds')
def ttg_tj_ds():
    start = request.args.get('start', "2025-01-01")
    end = request.args.get('end', "2025-12-31")
    r = TTG.analysis_tj(start,end)
    return jsonify(r)

# 打开未开始的比赛（正在售卖的比赛）
@app.route('/selling_hafu')
def selling_hafu():
    return render_template("selling_hafu.html")

@app.route('/getselling_hafu')
def getselling_hafu():
    r = selling.getSellingHafuDatas()
    return jsonify(r)

@app.route('/hafu')
def hafu():
    matchId = request.args.get('matchId')
    tp = request.args.get('tp')
    return render_template("hafu.html",matchId=matchId,tp=tp)


@app.route('/hafu_ds')
def hafu_ds():
    matchId = request.args.get('matchId')
    sim = request.args.get('sim',"0.31")
    tp = request.args.get('tp')
    r = HAFU.analysis(tp,matchId,float(sim))
    return jsonify(r)


# 打开未开始的比赛（胜平负正在售卖的比赛）
@app.route('/selling_hda')
def selling_hda():
    return render_template("selling_hda.html")

@app.route('/getselling_hda')
def getselling_hda():
    r = selling.getSellingHDADatas()
    return jsonify(r)

# 胜平负
@app.route('/hda')
def hda():
    matchId = request.args.get('matchId')
    tp = request.args.get('tp')
    return render_template("hda.html",matchId=matchId,tp=tp)


@app.route('/hda_ds')
def hda_ds():
    matchId = request.args.get('matchId')
    sim = request.args.get('sim',"0.31")
    tp = request.args.get('tp')
    single = request.args.get("single",None)
    if single == "0":
        single = None
    r = HDA.analysis(tp,matchId,float(sim),single)
    return jsonify(r)


# 开奖信息
@app.route('/kj')
def kj():
    return render_template("kj.html")

@app.route('/kj_ds')
def kj_ds():
    year = request.args.get('year')
    rang = request.args.get('rang')
    r = KJ.analysis(int(year),rang)
    return jsonify(r)


# 二串一信息
@app.route('/c21')
def c21():
    return render_template("c21.html")

@app.route('/c21_ds')
def c21_ds():
    year = request.args.get('year')
    r = C21.analysis(int(year))
    return jsonify(r)

# 三串一信息--一赔分析
@app.route('/c21_111')
def c21_111():
    return render_template("c21_111.html")

@app.route('/c21_111_ds')
def c21_111_ds():
    year = request.args.get('year')
    rang = request.args.get('rang')
    r = C21_111.analysis(int(year),rang)
    return jsonify(r)

# 三串一信息
@app.route('/c31')
def c31():
    return render_template("c31.html")

@app.route('/c31_ds')
def c31_ds():
    year = request.args.get('year')
    r = C31.analysis(int(year))
    return jsonify(r)


# 三串一信息--一赔分析
@app.route('/c31_111')
def c31_111():
    return render_template("c31_111.html")

@app.route('/c31_111_ds')
def c31_111_ds():
    year = request.args.get('year')
    rang = request.args.get('rang')
    r = C31_111.analysis(int(year),rang)
    return jsonify(r)



# 三串一胜平负信息
@app.route('/c31spf')
def c31spf():
    return render_template("c31spf.html")

@app.route('/c31spf_ds')
def c31spf_ds():
    year = request.args.get('year')
    r = C31spf.analysis(int(year))
    return jsonify(r)


# 三串一让球胜平负信息
@app.route('/c31rspf')
def c31rspf():
    return render_template("c31rspf.html")

@app.route('/c31rspf_ds')
def c31rspf_ds():
    year = request.args.get('year')
    r = C31rspf.analysis(int(year))
    return jsonify(r)


@app.route('/sxyc')
def sxyc():
    return render_template("sxyc.html")

@app.route('/sxyc_ds')
def sxyc_ds():
    r = SXYC.analysis()
    return jsonify(r)

@app.route('/sxyc_result')
def sxyc_result():
    return render_template("sxyc_result.html")

@app.route('/sxyc_result_ds')
def sxyc_result_ds():
    r = SXYC.analysis()
    return jsonify(r)
@app.route('/play')
def play():
    return render_template("play.html")

@app.route('/play_ds')
def play_ds():
    r = SXYC.play()
    return jsonify(r)



# 排列三，排列五
@app.route('/pailie')
def pailie():
    return render_template("pai3/pailie.html")

@app.route('/pailie_load')
def pailie_load():
    # loadPailieData.LoadDataPailie().loadData()
    loadPailieData.LoadDataPailie().uploadData()
    return "数据下载完成"

@app.route('/jihua_ds')
def jihua_ds():
    r = loadPailieData.LoadDataPailie().loadData()
    return jsonify(r)


# 计划单
@app.route('/jihua')
def jihua():
    return render_template("jihua/index.html")


if __name__ == '__main__':
    app.run(host="0.0.0.0",port=5000)
